package com.ar4j.handler;

import java.lang.reflect.Method;

import com.ar4j.ActiveRecordContext;
import com.ar4j.ActiveRecordMetadata;

import net.sf.cglib.proxy.MethodProxy;

/**
 * Defines API for handlers of active record methods
 */
public interface IMethodHandler {

  /**
   * Gives the handler to initialize before being run
   */
  void init(ActiveRecordMetadata metadata, Method method);
  
  /**
   * Handle the invocation of an active record method (or one from the base class)
   * 
   * @return the return value or null if there is none (void returns)
   */
  Object intercept(ActiveRecordMetadata metadata, ActiveRecordContext context, Object target, Method method, Object[] args, MethodProxy proxy)
    throws Throwable;
  
}
